using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.ComponentModel.Design;

namespace SLING
{
    public partial class MainForm : Form
    {

       
        public MainForm()
        {                       
            InitializeComponent();
        }

        private void FileOpen_Click(object sender, EventArgs e)
        {
            OpenFileDialog odlg = new OpenFileDialog();

            odlg.InitialDirectory = @"C:\ARM200\WORK";
            odlg.Title = "Open File";
            odlg.Filter = "S files (*.s)|*.s|All files (*.*)|*.*";

            if (odlg.ShowDialog() == DialogResult.OK)
            {
                //tempTextBox.Clear();

                int counter = 0;
                string line;

                ArrayList lines = new ArrayList();

                // Read the file and display it line by line.
                listBox1.BeginUpdate();
                System.IO.StreamReader file =
                    new System.IO.StreamReader(odlg.FileName);
                while ((line = file.ReadLine()) != null)
                {
                    lines.Add(line);
                    counter++;

                    listBox1.Items.Add(line + Environment.NewLine);

                }
                listBox1.EndUpdate();

                Manager.GetInstance().LoadFile(lines);

                file.Close();

               }               
               odlg.Dispose();
               //LoadFileActions();
            }

        private void LoadFileActions()
        {

            this.manager.LoadSource(source);            

            this.currentLineNumber = this.manager.CurrentLineNumber;                       
            listBox1.BeginUpdate();
            this.listBox1.SelectedIndex = this.manager.CurrentLineNumber;
            listBox1.EndUpdate();
            lineNoTextBox.Text = this.manager.CurrentLineNumber.ToString();
            this.firstTextBox.Text = this.manager.CurrentLine;

            this.lrTextBox.Text = this.manager.CurrentInstruction.ToString();
            //this.lrTextBox.Text = Enum.Parse(ARMInstruction,this.manager.CurrentInstruction);
        }

        private void FileExit_Click(object sender, EventArgs e)
        {
            Manager.GetInstance().Stop();
            this.Close();
        }

        private void CPU_Shutdown_Click(object sender, EventArgs e)
        {
            Manager.GetInstance().Stop();
        }

        private void Help_About_Click(object sender, EventArgs e)
        {
            MessageBox.Show(" SLING ARM Support Tool \n Jonathan Oliver \n Bournemouth University \n BSc Computing (Hons) \n 09.04.07");
        }

        private void goToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Manager.GetInstance().Run();
        }
    }
}